package com.boonya.springcloud.utils;

import org.apache.commons.lang.StringUtils;
import java.util.List;
import java.util.StringTokenizer;
import java.util.Vector;

/**
 * @ClassName: TokenSplit
 * @Description: TODO(功能说明)
 * @author: pengjunlin
 * @motto: 学习需要毅力，那就秀毅力
 * @date 2021/4/23 10:18
 */
public class TokenSplit {

    /**
     * 获取token封装的值
     *
     * @param token
     * @param split
     * @return
     * @throws Exception
     */
    public static Vector<String> getArrays(String token, String split) throws Exception{
        Vector<String> list = new Vector<>();
        StringTokenizer st = new StringTokenizer(token,split);
        String temp;
        int index =0;
        while (st.hasMoreTokens()){
            temp = st.nextToken();
            if(StringUtils.isNotEmpty(temp)
                && !"null".equalsIgnoreCase(temp)){
                list.add(temp);
            }else{
                throw new Exception("index of token is null ,index = "+index);
            }
            index++;
        }
        return list;
    }

    public static void main(String[] args) {
        String token = "huhsudf@jisd@7817832@8924jssss@user@pwd";
        List<String> list;
        try {
            list = TokenSplit.getArrays(token,"@");
            list.forEach(str->{
                System.out.println(str);
            });
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
